#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
using namespace std;


vector<int> findErrorNums(vector<int>& nums){
    vector<int> errorNums(2);
    int n = nums.size();
    sort(nums.begin(), nums.end());
    int prev = 0;
    for (int i = 0; i < n; i++) {
        int curr = nums[i];
        if (curr == prev) {
            errorNums[0] = prev;
        } else if (curr - prev > 1) {
            errorNums[1] = prev + 1;
        }
        prev = curr;
    }
    if (nums[n - 1] != n) {
        errorNums[1] = n;
    }
    return errorNums;
}

// 哈希表
vector<int> hashfindErrorNums(vector<int>& nums) {
        vector<int> errorNums(2);
        int n = nums.size();
        unordered_map<int, int> mp;
        for (auto& num : nums) {
            mp[num]++;
        }
        for (int i = 1; i <= n; i++) {
            int count = mp[i];
            if (count == 2) {
                errorNums[0] = i;
            } else if (count == 0) {
                errorNums[1] = i;
            }
        }
        return errorNums;
    }

int main(){
    vector<int> nums = { 1,2,2,4 }; 
    vector<int> out = findErrorNums(nums);
    cout << "[" << out[0] << "," << out[1] << "]"<<endl;
    return 0;
}